package org.cmroot.certmaster.service;

import org.bouncycastle.jce.PKCS10CertificationRequest;
import sun.security.util.ObjectIdentifier;
import java.security.GeneralSecurityException;
import java.security.cert.PKIXCertPathBuilderResult;
import java.security.cert.X509Certificate;
import java.util.*;

/**
 * Copyright (c) 2010 Andrey Domas <andrey.domas at gmail.com>.
 * *
 * This file is part of certmaster.
 * *
 * Certmaster is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * *
 * Certmaster is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see http://www.gnu.org/licenses
 * or write to the Free Software Foundation,Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301  USA
 */

public interface PKIEngine {

    public byte[] readRequest(String pem) throws PKIEngineException;

    /**
     *
     * @param der
     * @return List of objects: 0 - String CN, 1 - DER encoded attributes
     * @throws PKIEngineException
     */
    public List readRequest(byte[] der);

    public Set<X509Certificate> readCert(String pem) throws PKIEngineException;

    public Set<X509Certificate> readCert(byte[] der) throws PKIEngineException;

    public PKIXCertPathBuilderResult verifyChain(X509Certificate rootCert,
                                                          List<X509Certificate> interCerts,
                                                          X509Certificate endCert)
            throws GeneralSecurityException;


    public byte[] getExtension(byte[] der, ObjectIdentifier oid) throws PKIEngineException;

    public String derDecoder(byte data[]) throws PKIEngineException;

    public X509Certificate signRequest(byte[] requestDer, X509Certificate ca) throws PKIEngineException;
}
